//
//  STBasicTableVC.swift
//  Demo-04-TabBarTest
//
//  Created by 苏统世 on 16/5/10.
//  Copyright © 2016年 SuTon. All rights reserved.
//

import UIKit

class STBasicTableVC: UITableViewController {

    var isLogin:Bool = STUserAccountViewModel.shareManager.isUserLogin
    // MARK: - 懒加载
    lazy var visitorView:STVisitorView = STVisitorView()
    
    override func loadView() {
        if isLogin{
            super.loadView()
            
        }else{
            view = visitorView
            visitorView.delegate=self
            // is: 判断一个对象是否是指定类型
            if self is STHomeVC {
                visitorView.startRotationAnimation()
            } else if self is STMessagesVC {
                visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            } else if self is STSearchVC {
                visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            } else if self is STMeVC {
                visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            }
            setupDefaultNavigationItem()
        }
    }
    // MARK: - 设置默认 NavigationItem
    func setupDefaultNavigationItem(){
        navigationItem.leftBarButtonItem=UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickRegister"))
        navigationItem.rightBarButtonItem=UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("visitorViewDidClickLogin"))
    }
}

extension STBasicTableVC:STVisitorViewDelegate{
    func visitorViewDidClickRegister() {
        STPrint(items: "点击了访客视图的 【注册】")
    }
    
    func visitorViewDidClickLogin() {
        STPrint(items: "点击了访客视图的 【登陆】")
        // Modal出授权控制器       
        let nav = UINavigationController(rootViewController: STOauthVC())
        self.presentViewController(nav, animated: true, completion: nil)
    }
}

